﻿using System;
using System.Collections.Generic;
using System.Windows;
using Microsoft.Phone.Marketplace;


namespace EbbinghausWord.BLL
{
    /// <summary>
    /// 用户配置管理类
    /// </summary>
    public static class SystemConfig
    {
        #region private field

#if FREE
        private static readonly string _appTitle = "极速背单词 免费版";
        //private static readonly string _appId = "a276080f-af9d-474f-81ea-0753baead6dd";
        private static readonly string _appCode = "free";
#else
        private static readonly string _appTitle = "极速背单词 完全版";
        //private static readonly string _appId = "fbb78ae3-e82c-468b-808a-3df7828e7c83";
        private static readonly string _appCode = "paid";
#endif



        /// <summary>
        /// 是否试用版
        /// </summary>
        private static bool _isTrial = false;

        /// <summary>
        /// 版本
        /// </summary>
        private static readonly string _version = "1.3";

        private static readonly int _minQueueWordCount = 7;
        private static readonly int _increaseQueueWordCount = 7;

        /// <summary>
        /// 新词变成学习中之前，需要记忆的次数
        /// </summary>
        private static readonly int _newWordRemeberTimes = 3;

        /// <summary>
        /// 遗忘曲线时间点
        /// </summary>
        private static readonly List<TimeSpan> _forgetTimePoint = new List<TimeSpan>()
                                                                      {
                                                                          TimeSpan.FromMinutes(0),
                                                                          TimeSpan.FromMinutes(3),
                                                                          TimeSpan.FromMinutes(7),
                                                                          TimeSpan.FromHours(3),
                                                                          TimeSpan.FromHours(9),
                                                                          TimeSpan.FromHours(22),
                                                                          TimeSpan.FromDays(2),
                                                                          TimeSpan.FromDays(3),
                                                                          TimeSpan.FromDays(5),
                                                                          TimeSpan.FromDays(7),
                                                                          TimeSpan.FromDays(50000),

                                                                          //TimeSpan.FromSeconds(2),
                                                                          //TimeSpan.FromSeconds(5),
                                                                          //TimeSpan.FromSeconds(8),
                                                                          //TimeSpan.FromSeconds(10),
                                                                          //TimeSpan.FromDays(10),
                                                                      };

        /// <summary>
        /// 成绩系数
        /// </summary>
        private static readonly double[] _scoreRatio = new double[] { 0.10, 0.20, 0.30, 0.40, 0.55, 0.70, 0.80, 0.90, 1, 0 };
        /// <summary>
        /// 成绩总分
        /// </summary>
        private static double _totalScore = 100;
        private static readonly string _userWorkBookFileName = "userwordbook.dat";
        private static readonly string _backupFileName = "backup.dat";

        #endregion

        #region public property

        /// <summary>
        /// 备份文件路径
        /// </summary>
        public static string BackupFileName
        {
            get { return _backupFileName; }
        }

        /// <summary>
        /// 用户单词本路径
        /// </summary>
        public static string UserWordkBookFileName
        {
            get { return _userWorkBookFileName; }
        }

        /// <summary>
        /// 学习曲线的时间点
        /// </summary>
        public static List<TimeSpan> ForgetTimePoint
        {
            get { return _forgetTimePoint; }
        }

        /// <summary>
        /// 获得彻底记住单词的 记忆等级，这里采用了记忆等级来表示单词是否彻底被记住
        /// </summary>
        public static int AchievementRememberLevel
        {
            get
            {
                return _forgetTimePoint.Count - 2;
            }
        }

        /// <summary>
        /// 最小队列单词数
        /// </summary>
        public static int MinQueueWordCount { get { return _minQueueWordCount; } }

        /// <summary>
        /// 每次增加的单词数
        /// </summary>
        public static int IncreaseQueueWordCount { get { return _increaseQueueWordCount; } }

        /// <summary>
        /// 应用程序版本号
        /// </summary>
        public static string Version
        {
            get { return _version; }
        }

        /// <summary>
        /// 成绩系数
        /// </summary>
        public static double[] ScoreRatio
        {
            get
            {
                return _scoreRatio;
            }
        }

        /// <summary>
        /// 成绩总分
        /// </summary>
        public static double TotalScore { get { return _totalScore; } }

        /// <summary>
        /// 成绩文件
        /// </summary>
        public static string ScoreFileName
        {
            get
            {
                return string.Format("score{0}.dat", new UserConfig().UserBookId);
            }
        }

        /// <summary>
        /// 新词变成学习中之前，需要记忆的次数
        /// </summary>
        public static int NewWordRemeberTimes
        {
            get { return _newWordRemeberTimes; }
        }

        /// <summary>
        /// 应用名称
        /// </summary>
        public static string AppTitle
        {
            get { return _appTitle; }
        }

        /// <summary>
        /// 应用的Guid
        /// </summary>
        //public static string AppId
        //{
        //    get { return _appId; }
        //}

        /// <summary>
        /// 应用的专有编号
        /// </summary>
        public static string AppCode
        {
            get
            {
                return IsTrial ? "trial" : _appCode;
            }
        }

        /// <summary>
        /// 是否试用版
        /// </summary>
        public static bool IsTrial
        {
            get
            {
                return _isTrial;
            }
        }
        #endregion

        #region public method

        public static void CheckLicense()
        {
#if DEBUG
            string message = "是否试用版";
            if (MessageBox.Show(message, "试用版调试",
                 MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                _isTrial = true;
            }
            else
            {
                _isTrial = false;
            }
#else
            _isTrial = new LicenseInformation().IsTrial();
#endif
        }
        #endregion
    }
}
